# -*- coding: utf-8 -*-
# from __future__ import division

class MajorityVoter:
    # 类别对多个（5 个或更多？无论如何是奇数）分类进行多数投票
    def __init__(self, prediction_list):
        # self.predictions = prediction_list
        self.predictions = []
        self.ones = []
        self.zeros = []
        
        for p, l in prediction_list:
            self.predictions.append(p)
            if p == 0:
                self.zeros.append(l)
            elif p == 1:
                self.ones.append(l)
        
    # 总体预测如果超过一半的预测结果为 1，则返回 1
    def vote(self):
        if sum(self.predictions) > len(self.predictions)/2.0:
            return 1, self.ones[0]
        else:
            return 0, self.zeros[0]
